Questões

Questão 1

MRT_1F <-c(517.1468515630205, 85.13094142168089, 30.333207896694553, 12.694776264558937, 3.3041601673945418, 1.1823111717498882, 1.1892293502386786)
MRT_3F <-c(156.68929936163462, 11.540837783562276, 0.4512835621696538, 0.4509797929766453, 0.4502068233039181, 0.4496185276300172, 0.4543157082191288)
MRT_5F <-c(83.90319666471157, 0.3068151086494968, 0.30522314133037304, 0.3072588968084928, 0.30655265997285697, 0.3055812715727718, 0.3053297166713006)
MRT_10F <-c(29.55430642951759, 0.19832832665772515, 0.1971923924717474, 0.19796648905716516, 0.19615594370806338, 0.2034569237883263, 0.19617420889447737)
MRT_15F <-c(11.317736530583566, 0.167364215666193, 0.16172168266811013, 0.16701085329580515, 0.1598052657153692, 0.1645934043532696, 0.16216563797118075)
MRT_sem_F <-c(11.93430909937736, 0.6095414637034009, 0.6060645101029295, 0.612167181646899, 0.6146761002685637, 0.6096747087200697, 0.6125810476877268)
clock <- c(0.1, 0.5, 1, 1.5, 2, 2.5, 3)

par(mar = c(5, 4, 4, 4) + 0.1)
plot(clock, MRT_1F, col = "black",type = "o", ylim = range(MRT_1F, MRT_3F, MRT_5F, MRT_10F, MRT_15F, MRT_sem_F), 
     xlab = "Time between Things Request (seconds)", 
     ylab = "Response Time (sec.)", main = "Gráfico de Linhas", pch = 4)
lines(clock, MRT_3F, col = "yellow", type = "o", pch = 11)
lines(clock, MRT_5F, col = "red", type = "o", pch = 1)
lines(clock, MRT_10F, col = "blue", type = "o", pch = 2)
lines(clock, MRT_15F, col = "purple", type = "o", pch = 5)
lines(clock, MRT_sem_F, col = "green", type = "o", pch = 4)
legend("topright", legend = c("MRT_1F", "MRT_3F", "MRT_5F", "MRT_10F", "MRT_15F", "MRT_sem_F"), 
       col = c("black", "yellow", "red", "blue", "purple", "green"), lty = 1, pch = c(4, 11, 1, 2, 5, 4))

layout(matrix(1:6, nrow = 2, byrow = TRUE))

data_matrix <- rbind(MRT_sem_F, MRT_1F)
data_matrix <- log(data_matrix)
colors <- c("#E6E6E6", "#666666")

barplot(data_matrix, beside = TRUE, col = colors,
        main = "1 Fog", xlab = "Time between Things requests", ylab = "Response time (s)",
        names.arg = clock)

legend("topright", legend = c("MRT_sem_F", "MRT_1F"), fill = colors)


data_matrix <- rbind(MRT_sem_F, MRT_3F)
data_matrix <- log(data_matrix)

barplot(data_matrix, beside = TRUE, col = colors,
        main = "3 Fog", xlab = "Time between Things requests", ylab = "Response time (s)",
        names.arg = clock)

legend("topright", legend = c("MRT_sem_F", "MRT_3F"), fill = colors)


data_matrix <- rbind(MRT_sem_F, MRT_5F)
data_matrix <- log(data_matrix)

barplot(data_matrix, beside = TRUE, col = colors,
        main = "5 Fog", xlab = "Time between Things requests", ylab = "Response time (s)",
        names.arg = clock)

legend("topright", legend = c("MRT_sem_F", "MRT_5F"), fill = colors)


data_matrix <- rbind(MRT_sem_F, MRT_10F)
data_matrix <- log(data_matrix)

barplot(data_matrix, beside = TRUE, col = colors,
        main = "10 Fog", xlab = "Time between Things requests", ylab = "Response time (s)",
        names.arg = clock)

legend("topright", legend = c("MRT_sem_F", "MRT_10F"), fill = colors)


data_matrix <- rbind(MRT_sem_F, MRT_15F)
data_matrix <- log(data_matrix)

barplot(data_matrix, beside = TRUE, col = colors,
        main = "15 Fog", xlab = "Time between Things requests", ylab = "Response time (s)",
        names.arg = clock)

legend("topright", legend = c("MRT_sem_F", "MRT_15F"), fill = colors)

Questão 2

meal_price <- c("$10-19", "$20-29", "$30-39", "$40-49")
Good <- c(53.8, 33.9, 2.6, 0.0)
Very_Good <- c(43.6, 54.2, 60.5, 21.4)
Excellent <- c(2.6, 11.9, 36.8, 78.6)

data_matrix <- rbind(Good, Very_Good, Excellent)

colors <- c("green", "lightblue", "blue")

barplot(data_matrix, beside = FALSE, col = colors,
        main = "Quality Rating by Meal Price", xlab = "Meal Price ($)", ylab = "Percentage (%)",
        names.arg = meal_price)

legend("topright", legend = c("Good", "Very Good", "Excellent"), fill = colors)

Questão 3

data("airquality")
airquality <- airquality[airquality$Month == 5, ]
airquality$Temp <- (airquality$Temp-32)/1.8
hist(airquality$Temp, main = "Histograma das Temperaturas em Maio (°C)", 
     xlab = "Temperatura (°C)", 
     ylab = "Frequência",
     col = "lightblue", 
     border = "black", 
     prob = TRUE, )
lines(density(airquality$Temp), col = "red")

Questão 4

sales <- read.table("https://training-course-material.com/images/8/8f/Sales.txt",header=TRUE)

paises <- sales$COUNTRY
vendas <- sales$SALES
vendas_perc <- vendas / sum(vendas) * 100
labels <- paste(vendas, " (", round(vendas_perc, 1), "%)", sep="")
colors <- c("blue", "lightblue", "lightgreen", "orange", "yellow", "red")

pie(vendas_perc, labels = labels, col = colors, 
    main = "Total e Percentual de Vendas por País")

legend("topleft", legend = paises, fill = colors)

Questão 5

data(InsectSprays)

boxplot(count ~ spray, data = InsectSprays,
        outline = FALSE,
        main = "Gráfico BoxPlot - Quantidade de Spray por Tipo",
        xlab = "Tipos de Spray",
        ylab = "Quantidade",
        col = "yellow"
        )

Questão 6

dados_NONE <- read.csv("monitoringCloudData_NONE.csv")
dados_0.1 <- read.csv("monitoringCloudData_0.1.csv")
dados_0.5 <- read.csv("monitoringCloudData_0.5.csv")
dados_1 <- read.csv("monitoringCloudData_1.csv")

dados_NONE <- dados_NONE[, c("currentTime", "usedMemory")]
dados_0.1 <- dados_0.1[, c("currentTime", "usedMemory")]
dados_0.5 <- dados_0.5[, c("currentTime", "usedMemory")]
dados_1 <- dados_1[, c("currentTime", "usedMemory")]

ajustar_dados <- function(dados) {
  dados$currentTime <- strptime(dados$currentTime, "%Y-%m-%d %H:%M:%S")
  dados$currentTime <- difftime(dados$currentTime, dados$currentTime[1], units = "hours")
  
  dados$usedMemory_unidade_orig <- gsub("[0-9.]", "", dados$usedMemory)
  dados$usedMemory_orig <- as.numeric(gsub("[^0-9.]", "", dados$usedMemory))
  
  dados$usedMemory <- ifelse(dados$usedMemory_unidade_orig == "TB", dados$usedMemory_orig * 1000000,
                             ifelse(dados$usedMemory_unidade_orig == "GB", dados$usedMemory_orig * 1024,
                                    dados$usedMemory_orig))
  return(dados)
}

dados_NONE <- ajustar_dados(dados_NONE)
dados_0.1 <- ajustar_dados(dados_0.1)
dados_0.5 <- ajustar_dados(dados_0.5)
dados_1 <- ajustar_dados(dados_1)

layout(matrix(1:4, nrow = 2, byrow = TRUE))

plot(dados_NONE$currentTime, dados_NONE$usedMemory, type = "l", col = "black", xlab = "Time (hour)", ylab = "Used Memory (MB)")
plot(dados_0.1$currentTime, dados_0.1$usedMemory, type = "l", col = "black", xlab = "Time (hour)", ylab = "Used Memory (MB)")
plot(dados_0.5$currentTime, dados_0.5$usedMemory, type = "l", col = "black", xlab = "Time (hour)", ylab = "Used Memory (MB)")
plot(dados_1$currentTime, dados_1$usedMemory, type = "l", col = "black", xlab = "Time (hour)", ylab = "Used Memory (MB)")

Questão 7

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(plotly)
## Carregando pacotes exigidos: ggplot2
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
dados <- read.csv("netflix_titles.csv")

dados_filtrados <- dados %>%
  filter(!is.na(country) & country != "") %>%
  filter(!grepl(",", country))

conteudos_por_pais <- dados_filtrados %>%
  count(country) %>%
  arrange(desc(n)) %>%
  slice(1:10)

plot_ly(conteudos_por_pais, labels = ~country, values = ~n, type = 'pie') %>%
  layout(title = 'Top 10 países com mais conteúdo na Netflix',
         xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
         yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))

Questão 8

df <- data.frame(conteudos_por_pais)
colnames(df) <- c("País", "Total de conteúdos")
pais <- as.list(df$País)
total_conteudos <- as.list(df$`Total de conteúdos`)

plot_ly(
  type = "table",
  header = list(
    values = names(df),
    fill = list(color = "gray"),
    font = list(color = "white"),
    align = "center"
  ),
  cells = list(
    values = list(pais, total_conteudos),
    align = "center"
  )
)

Questão 9

dados$decada <- as.numeric(substr(dados$release_year, 1, 3)) * 10

dados_por_decada <- dados %>%
  filter(!is.na(release_year)) %>%
  group_by(decada, type) %>%
  summarise(contagem = n()) %>%
  ungroup()
## `summarise()` has grouped output by 'decada'. You can override using the
## `.groups` argument.
plot_ly(dados_por_decada, x = ~decada, y = ~contagem, color = ~type,
                   type = 'scatter', mode = 'lines+markers', colors = c('yellow', 'blue')) %>%
  layout(#title = 'Quantidade de Conteúdo por Década na Netflix',
         xaxis = list(title = 'Década'),
         yaxis = list(title = 'Qnd. Conteúdo'),
         legend = list(title = 'Tipo de Conteúdo', 
                       x = 1, y = 0.95))

Questão 10

filmes20002010 <- dados %>%
  filter(type == "Movie", release_year > 2000, release_year < 2010)

filmes20002010$primeiro_genero <- sub(",.*", "", filmes20002010$listed_in)

filmes20002010$primeiro_genero <- factor(filmes20002010$primeiro_genero,
                                       levels = c("Dramas", "Action & Adventure", "Comedies"))


filmes20002010$primeiro_genero <- recode(filmes20002010$primeiro_genero, "Dramas" = "Drama", "Action & Adventure" = "Ação e Aventura", "Comedies" = "Comédia")

dados_agrupados <- filmes20002010 %>%
  group_by(release_year, primeiro_genero) %>%
  summarise(contagem = n()) %>%
  filter(primeiro_genero %in% c("Drama", "Ação e Aventura", "Comédia")) %>%
  ungroup()
## `summarise()` has grouped output by 'release_year'. You can override using the
## `.groups` argument.
plot_ly(dados_agrupados, x = ~release_year, y = ~contagem, color = ~primeiro_genero,
        type = 'bar', width = 0.5) %>%
  layout(title = 'Quantidade de Filmes por Gênero entre 2000 e 2010',
         xaxis = list(title = 'Ano de Lançamento'),
         yaxis = list(title = 'Qnt. de Lançamentos'),
         barmode = 'group',
         legend = list(title = 'Gênero'))